
# 视频保图像
import cv2

"""打开视频"""

def video_pic(path):
    cap = cv2.VideoCapture(path)
    sucess = cap.isOpened()
    frame_count = 0
    i = 0
    while sucess:
        frame_count += 1
        sucess, frame = cap.read()
        if (frame_count % 1 == 0):    # 可以调整数字，缩小裁切间隔
            i += 1
            cv2.imwrite('D:\\python\\datasets\\img3\\s%d.jpg' % i, frame)  # 名字可改
            print(i)
    cap.release()

if __name__ == '__main__':
    path = "D:\\python\\datasets\\video\\test9.mp4"
    video_pic(path)








